import java.util.Comparator;
import java.util.PriorityQueue;

class IntCmp implements Comparator<Integer> {
    
    @Override
    public int compare(Integer o1, Integer o2) {
        //return o2 - o1;
        return o2.compareTo(o1);
    }
}

public class Test {
    public int[] smallestK(int[] arr, int k) {
        int[] ret = new int[k];
        if (arr == null || k == 0) {
            return ret;
        }
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp());
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            int top = priorityQueue.peek();
            if (arr[i] < top) {
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        for (int i = 0; i < k; i++) {
            ret[i] = priorityQueue.poll();
        }
        return ret;
    }

    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();

        priorityQueue.offer(10);
        priorityQueue.offer(5);
        priorityQueue.offer(9);
        priorityQueue.offer(7);
        priorityQueue.offer(77);
        //priorityQueue.offer(null);

        System.out.println(priorityQueue.poll());
    }

    public static void main1(String[] args) {
        MyPriorityQueue myPriorityQueue = new MyPriorityQueue();
        int[] array = {27, 15, 19, 18, 28, 34, 65, 49, 25, 37};
        myPriorityQueue.createHeap(array);
        System.out.println("================");
        myPriorityQueue.push(80);
        System.out.println("================");
        System.out.println(myPriorityQueue.poll());
    }
}
